/*
 * @lc app=leetcode.cn id=165 lang=cpp
 *
 * [165] 比较版本号
 */

// @lc code=start
class Solution {
public:
    int compareVersion(string version1, string version2) {
        //每次读取.间隔的数字
        //需要读取长度长的字符串所有内容
        for(int i = 0, j = 0; i < version1.size() || j < version2.size();){
            int x = i, y = j;
            while(x < version1.size() && version1[x] != '.') x++;
            while(y < version2.size() && version2[y] != '.') y++;
            int t1, t2;
            t1 = (x == i) ? 0 : stoi(version1.substr(i, x - i));
            t2 = (y == j) ? 0 : stoi(version2.substr(j, y - j));
            if(t1 < t2) return -1;
            else if (t1 > t2) return 1;
            i = x + 1; j = y + 1;
        }
        return 0;
    }
};
// @lc code=end

